package com.znsb.msfq.utils;

import java.text.NumberFormat;

/**
 * Created by yg846 on 2016/12/11.
 */
public class StringUtils {

    /**
     * 判断对象是否不为null
     *
     * @param object
     * @return
     */
    public static boolean isNotNull(Object object){
        return !isNull(object);
    }

    /**
     * 判断对象是否为null,不允许空白串
     *
     * @param object    目标对象类型
     * @return
     */
    public static boolean isNull(Object object){
        if ((""+object).equals("null")) {
            return true;
        }
        if ((object instanceof String)){
            return "".equals(((String)object).trim());
        }

        return false;
    }

    //保留小数位数
    public static String doubleFormateStr(String str) {
        NumberFormat nf = NumberFormat.getNumberInstance();
        nf.setMaximumFractionDigits(2);
        str = nf.format(Double.parseDouble(str));
        return str;
    }
    //手机号码
    public static String Phone(String phone) {
        if (isNotNull(phone)){
            if (phone.length()>10){
                phone=phone.substring(0,3)+"****"+phone.substring(7,phone.length());
            }
        }

        return phone;
    }
}
